package com.csdn.listener;

import com.csdn.config.BaseConfig;
import com.csdn.config.Desc;
import org.reflections.Reflections;

import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public class ConfigClassResolver {
    private static Map<String, Class<? extends BaseConfig>> classMap;

    static {
        Reflections reflections = new Reflections("com.csdn");
        Set<Class<? extends BaseConfig>> subTypesOf = reflections.getSubTypesOf(BaseConfig.class);
        classMap = subTypesOf.stream().collect(Collectors.toMap(s -> s.getDeclaredAnnotation(Desc.class).value(), s -> s));
    }

    public static Map<String, Class<? extends BaseConfig>> getClassMap() {
        return classMap;
    }
}
